import http from '@/utils/request';

interface MyRequestOptions {
	url : string;
	method : 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
	data ?: Record<string, unknown>;
	ticket ?: number;
}
/**
 * @description: 查询保养计划列表
 */
export async function getSelectList(data) : Promise<any> {
	const options : MyRequestOptions = {
		url: '/keepPlan/selectList',
		method: 'POST',
		data: data,
		ticket: 1, // 为1带satoken
	};
	try {
		const response = await http.globalRequest(options);
		if (response.code === 2000) {
			return response.data;
		} else { throw response.msg }
	} catch (error) {
		throw error;
	}
}
/**
 * @description: 设备巡检-根据设备编号查询设备信息
 */
export async function getEqupInspection(data) : Promise<any> {
	const options = {
		url: '/keepPlan/equpInspection',
		method: 'GET',
		ticket: 1, // 为1带satoken
		data: data
	};
	try {
		const response = await http.globalRequest(options);
		if (response.code === 2000) {
			return response.data;
		} else { throw response.msg }
	} catch (error) {
		throw error;
	}
}
/**
 * @description: 保养登记
 */
export async function setKeepResult(data) : Promise<any> {
	const options : MyRequestOptions = {
		url: '/keepPlan/addKeepResult',
		method: 'POST',
		data: data,
		ticket: 1, // 为1带satoken
	};
	try {
		const response = await http.globalRequest(options);
		if (response.code === 2000) {
			return response;
		} else { throw response.msg }
	} catch (error) {
		throw error;
	}
}
/**
 * @description: 根据设备编号查询设备信息
 */
export async function getKeepPlanByBarcode(data) : Promise<any> {
	const options : MyRequestOptions = {
		url: '/keepPlan/queryKeepPlanByBarcode',
		method: 'GET',
		data: data,
		ticket: 1, // 为1带satoken
	};
	try {
		const response = await http.globalRequest(options);
		if (response.code === 2000) {
			return response.data;
		} else { throw response.msg }
	} catch (error) {
		throw error;
	}
}
/**
 * @description: 根据设备编号查询设备信息
 */
export async function setEqupInspection(data) : Promise<any> {
	const options : MyRequestOptions = {
		url: '/keepPlan/addEqupInspection',
		method: 'POST',
		data: data,
		ticket: 1, // 为1带satoken
	};
	try {
		const response = await http.globalRequest(options);
		if (response.code === 2000) {
			return response;
		} else { throw response.msg }
	} catch (error) {
		throw error;
	}
}